package guda.mrpc.core;


import guda.mrpc.core.common.Constants;

/**
 * Created by well on 17/5/24.
 */
public class RequestKey {


    private String interfaceName;
    private String version;
    private String group;

    public RequestKey(String interfaceName) {
        this(interfaceName, Constants.DEFAULT_SERVICE_GROUP_NAME, Constants.DEFAULT_SERVICE_VERSION);
    }


    public RequestKey(String interfaceName, String version) {
        this(interfaceName, Constants.DEFAULT_SERVICE_GROUP_NAME, version);
    }

    public RequestKey(String interfaceName, String group, String version) {
        this.interfaceName = interfaceName;
        if (version != null) {
            this.version = version;
        } else {
            this.version = Constants.DEFAULT_SERVICE_VERSION;
        }
        if (group != null) {
            this.group = group;
        } else {
            this.group = Constants.DEFAULT_SERVICE_GROUP_NAME;
        }

    }


    public String getInterfaceName() {
        return interfaceName;
    }

    public void setInterfaceName(String interfaceName) {
        this.interfaceName = interfaceName;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    public String toString() {
        StringBuilder buf = new StringBuilder();
        buf.append("group=").append(group).append("&interfaceName=")
                .append(interfaceName).append("&version=").append(version);
        return buf.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        RequestKey that = (RequestKey) o;

        if (!interfaceName.equals(that.interfaceName)) return false;
        if (!version.equals(that.version)) return false;
        return group.equals(that.group);

    }

    @Override
    public int hashCode() {
        int result = interfaceName.hashCode();
        result = 31 * result + version.hashCode();
        result = 31 * result + group.hashCode();
        return result;
    }
}
